﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing.Design;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.ComponentModel;
using System.Windows.Forms.Design;

namespace WCFLOBTalk.SalesForceWCF.Helpers
{
    public class LoadFromConfigEditor : UITypeEditor 
    {
        public string PathToFile { get; set; }

        private OpenFileDialog FilePicker = new OpenFileDialog();

        public LoadFromConfigEditor()
        {
            PathToFile = "";


            // Setup the FilePicker
            FilePicker.Title = "Choose config file to open.";
            FilePicker.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            FilePicker.Filter = "Config Files (*." + "config" + ")|*." + "config";
   

            FilePicker.Multiselect = false;


        }

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context != null)
            {
                return UITypeEditorEditStyle.Modal; 
            }
            else {
                return base.GetEditStyle(context);
            }
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            // Show the file picker


            if (FilePicker.ShowDialog() == DialogResult.OK)
            {
                PathToFile = FilePicker.FileName;
            }

            return PathToFile;

        }



    }
}
